package com.ruoyi.board.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.board.domain.MessageBoard;
import com.ruoyi.board.service.IMessageBoardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言表Controller
 * 
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/board/board")
public class MessageBoardController extends BaseController
{
    @Autowired
    private IMessageBoardService messageBoardService;

    /**
     * 查询留言表列表
     */
    @PreAuthorize("@ss.hasPermi('board:board:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageBoard messageBoard)
    {
        startPage();
        List<MessageBoard> list = messageBoardService.selectMessageBoardList(messageBoard);
        return getDataTable(list);
    }

    /**
     * 导出留言表列表
     */
    @PreAuthorize("@ss.hasPermi('board:board:export')")
    @Log(title = "留言表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageBoard messageBoard)
    {
        List<MessageBoard> list = messageBoardService.selectMessageBoardList(messageBoard);
        ExcelUtil<MessageBoard> util = new ExcelUtil<MessageBoard>(MessageBoard.class);
        util.exportExcel(response, list, "留言表数据");
    }

    /**
     * 获取留言表详细信息
     */
    @PreAuthorize("@ss.hasPermi('board:board:query')")
    @GetMapping(value = "/{MessageId}")
    public AjaxResult getInfo(@PathVariable("MessageId") Long MessageId)
    {
        return success(messageBoardService.selectMessageBoardByMessageId(MessageId));
    }

    /**
     * 新增留言表
     */
    @PreAuthorize("@ss.hasPermi('board:board:add')")
    @Log(title = "留言表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageBoard messageBoard)
    {
        return toAjax(messageBoardService.insertMessageBoard(messageBoard));
    }

    /**
     * 修改留言表
     */
    @PreAuthorize("@ss.hasPermi('board:board:edit')")
    @Log(title = "留言表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageBoard messageBoard)
    {
        return toAjax(messageBoardService.updateMessageBoard(messageBoard));
    }

    /**
     * 删除留言表
     */
    @PreAuthorize("@ss.hasPermi('board:board:remove')")
    @Log(title = "留言表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{MessageIds}")
    public AjaxResult remove(@PathVariable Long[] MessageIds)
    {
        return toAjax(messageBoardService.deleteMessageBoardByMessageIds(MessageIds));
    }
}
